<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">

  <!-- Copy all attributes and elements to the output. -->
  <xsl:template match="@*|*">
    <xsl:copy>
      <xsl:apply-templates select="@*" />
      <xsl:apply-templates select="*" />
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="wix:Wix">
    <xsl:copy>
      <xsl:processing-instruction name="include">../defines.wxi</xsl:processing-instruction>
      <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
  </xsl:template>
  
  <xsl:output method="xml" indent="yes" />

  <!-- Search directories for the components that will be removed. -->
  <xsl:key name="pdb-search" match="wix:Component[contains(wix:File/@Source, '.pdb')]" use="@Id"/>
  <xsl:key name="exe-config-search" match="wix:Component[contains(wix:File/@Source, '.exe.config')]" use="@Id"/>
  <xsl:key name="dll-config-search" match="wix:Component[contains(wix:File/@Source, '.dll.config')]" use="@Id"/>
  <xsl:key name="vshost-search" match="wix:Component[contains(wix:File/@Source, '.vshost.exe')]" use="@Id"/>
  <xsl:key name="manifest-search" match="wix:Component[contains(wix:File/@Source, '.manifest')]" use="@Id"/>
  <xsl:key name="metro-xml-search" match="wix:Component[contains(wix:File/@Source, 'MahApps.Metro.xml')]" use="@Id"/>
  <xsl:key name="p4-xml-search" match="wix:Component[contains(wix:File/@Source, 'p4api.net.xml')]" use="@Id"/>
  <xsl:key name="packages-search" match="wix:Directory[@Name = 'packages']" use="@Id" />
  <xsl:key name="target-exe-search" match="wix:Component[contains(wix:File/@Source, '.Toolkit.Host.exe')]" use="@Id"/>

  <!-- Remove components/refs referencing components in those directories. -->
  <xsl:template match="wix:Component[key('pdb-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('pdb-search', @Id)]" />
  <xsl:template match="wix:Component[key('exe-config-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('exe-config-search', @Id)]" />
  <xsl:template match="wix:Component[key('dll-config-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('dll-config-search', @Id)]" />
  <xsl:template match="wix:Component[key('vshost-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('vshost-search', @Id)]" />
  <xsl:template match="wix:Component[key('manifest-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('manifest-search', @Id)]" />
  <xsl:template match="wix:Component[key('metro-xml-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('metro-xml-search', @Id)]" />
  <xsl:template match="wix:Component[key('p4-xml-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('p4-xml-search', @Id)]" />
  <xsl:template match="wix:Directory[key('packages-search', @Id)]" />
  <xsl:template match="wix:Component[key('target-exe-search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('target-exe-search', @Id)]" />
  
  <!-- ### Adding the Win64-attribute to all Components -->
  <xsl:template match="wix:Component">
    <xsl:copy>
      <xsl:apply-templates select="@*" />
      <!-- Adding the Win64-attribute as we have a x64 application -->
      <xsl:attribute name="Win64">yes</xsl:attribute>
      <!-- Now take the rest of the inner tag -->
      <xsl:apply-templates select="node()" />
    </xsl:copy>
  </xsl:template>
  <xsl:template match="@type[parent::property]" />
</xsl:stylesheet>